package cn.panda.edu.controller;

import cn.panda.edu.model.Course;
import cn.panda.edu.service.CourseService;
import cn.panda.edu.util.Constant;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value="/api/admin")
@Api(description="课程管理")
public class ManageCourseController {
	
	@Autowired
	private CourseService courseService;
	
	/**
	 * 
	* @Title: coursemanageFy 
	* @Description: TODO(课程模糊查询分页) 
	* @param @param courseId
	* @param @param courseName
	* @param @param pageIndex
	* @param @return  
	* @return PageInfo<Course>
	 */
	@ApiOperation(value="课程模糊查询分页" , notes="")//用以指明api名称 
	@ApiImplicitParams({@ApiImplicitParam(name="courseName", value="课程名称", required=false, dataType="String",paramType="form"),
		               @ApiImplicitParam(name="pageIndex", value="页码", required=true, dataType="int",paramType="form")})	
	@RequestMapping(value = "/coursemanageFy",method = RequestMethod.POST)
	public Object coursemanageFy(@RequestParam(required=false) String condition, Integer pageIndex){

		PageInfo<Course> pageInfo=courseService.selectLikeByPrimaryKey( condition, pageIndex, Constant.PAGE_SIZE);
		return ResultDataUtil.resData(200, "", pageInfo) ;	
	}
	
	/**
	 * 
	* @Title: coursemanageSel 
	* @Description: TODO(根据id查询课程) 
	* @param @param courseId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据id查询课程" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="courseId", value="课程id", required=true, dataType="int",paramType="form")	
	@RequestMapping(value = "/coursemanageSel",method = RequestMethod.POST)
	public Map<String,Object> coursemanageSel(@RequestParam(required=true)Integer courseId){
		Course course=courseService.selectByPrimaryKey(courseId);		
		return ResultDataUtil.resData(200, "", course);		
	}
	/**
	 * 
	* @Title: coursemanageDel 
	* @Description: TODO(根据id删除课程) 
	* @param @param courseId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据id删除课程" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="courseId", value="课程id", required=true, dataType="int",paramType="form")	
	@RequestMapping(value = "/coursemanageDel",method = RequestMethod.POST)
	public Map<String,Object> coursemanageDel(@RequestParam(required=true)Integer courseId){
		Map<String,Object> map=new HashMap<>();
		int i=courseService.deleteByPrimaryKey(courseId);
		if(i>0) {
			map = ResultDataUtil.resData(200, "删除成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "删除失败",null) ;
		}
		return map;		
	}
	/**
	 * 
	* @Title: coursemanageUp 
	* @Description: TODO(修改课程) 
	* @param @param record
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="修改课程" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="record", value="课程对象", required=true, dataType="Course",paramType="form")	
	@RequestMapping(value = "/coursemanageUp",method = RequestMethod.POST)
	public Map<String,Object> coursemanageUp(Course record){
		Map<String,Object> map=new HashMap<>();
		int i=courseService.updateByPrimaryKeySelective(record);
		if(i>0) {
			map = ResultDataUtil.resData(200, "更新成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "更新失败",null) ;
		}
		return map;		
	}
	/**
	 * 
	* @Title: coursemanageAdd 
	* @Description: TODO(添加课程) 
	* @param @param record
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="添加课程" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="record", value="课程对象", required=true, dataType="Course",paramType="form")	
	@RequestMapping(value = "/coursemanageAdd",method = RequestMethod.POST)
	public Map<String,Object> coursemanageAdd(Course record){
		Map<String,Object> map=new HashMap<>();
		int i=courseService.insertSelective(record);
		if(i>0) {
			map = ResultDataUtil.resData(200, "添加成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "添加失败",null) ;
		}
		return map;		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
